var e, t = require("../../@babel/runtime/helpers/interopRequireDefault"),
  a = t(require("../../@babel/runtime/regenerator")),
  n = t(require("../../@babel/runtime/helpers/asyncToGenerator")),
  r = t(require("../../@babel/runtime/helpers/slicedToArray")),
  base = require("../../base.js"),
  c = getApp();

var list = require("../../datas/list.js");

Page({
  data: {
    questionCategory: "",
    bg_answer: "images/bg_answer.png",
    im_answer: "images/im_answer.png",
    icons: {
      icon05: base.IMGPATH + "ic_hot.png",
      icon07: base.IMGPATH + "xingxing.png",
      icon08: base.IMGPATH + "xingxing02.png",
      play: base.IMGPATH + "play.png",
      back: base.IMGPATH + "back.png"
    },
    list: [],
    result: null,
    topDistance: 0,
    backHeight: 0,
    backWidth: 0,
    leftDistance: 0,
    answerImg: base.IMGPATH + "qinggan.png",
    ans: ""
  },
  onLoad: function () {
    var e = this,
      t = c.globalData.headerBtnPosi,
      a = c.globalData.winWidth,
      n = t.top,
      r = a - t.right,
      i = t.height,
      s = 2 * i,
      o = this.data,
      u = o.bg_answer,
      l = o.im_answer,
      g = Math.ceil(2 * Math.random()),
      d = 1 == g ? u : l;
    this.setData({
      topDistance: n,
      leftDistance: r,
      answerImg: d,
      ans: g,
      backWidth: s,
      backHeight: i
    }, function () {
      e.setResult();
    });
  },
  setResult: function () {
    var e = this,
      t = wx.getStorageSync("questionAnswer"),
      a = t.questionCategory,
      n = t.answerList,
      i = t.answerResult,
      s = t.crossHeadList,
      o = t.answerType,
      c = t.title,
      u = {};
    if (i && n.forEach(function (e) {
        e.answerSeq == i && ((u = e).title = c);
      }), "STAR" == o) {
      var l = i && u.answerContent.split("/"),
        g = l[1] - l[0],
        d = parseInt(l[0]);
      u.x1 = new Array(g).fill(1), u.x2 = new Array(d).fill(1);
    } else if ("RANGE" == o) {
      var p = 0;
      s.forEach(function (e) {
        p += e.score;
      });
      for (var h = 0; h < n.length; h++) {
        var f = n[h],
          w = f.answerContent.split("-"),
          b = (0, r.default)(w, 2),
          y = parseInt(b[0]),
          m = parseInt(b[1]);
        if (p >= y && p <= m) {
          (u = f).scores = p;
          break;
        }
      }
    }
    u.answerType = o, this.setData({
      id: t.id,
      result: u,
      questionCategory: a,
      list: list.filter((e) => e.category_id == t.category_id),
    }, function () {
      e.fetchData();
    });
  },
  fetchData: (e = (0, n.default)(a.default.mark(function e() {
    var t, n, r, i;
    return a.default.wrap(function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return t = this.data, n = t.questionCategory, t.list, e.next = 3, (0, base.ajax)({
            url: "/Exam/paper_submit",
            data: {
              keyWord: "",
              pageSize: 5,
              pageNumber: 1,
              questionCategory: n
            }
          });

        case 3:
          if (!e.sent || !e.sent.data) {
            return e.next = "end";
          }
          (r = e.sent).code || ((i = r.data.data).length && i.forEach(function (e) {
            e.reads = (0, base.getRandomNumberByRange)(1e3, 1e5);
          }), this.setData({
            list: i
          }));

        case 5:
        case "end":
          return e.stop();
      }
    }, e, this);
  })), function () {
    return e.apply(this, arguments);
  }),
  onShareAppMessage: function (e) {
    var t = wx.getStorageSync("questionAnswer"),
      a = t.id;
    return {
      title: t.title,
      imageUrl: t.coverImgUrl,
      path: "".concat("/pages/detail/index", "?id=").concat(a)
    };
  },
  jumpDetail: function (e) {
    var t = e.currentTarget.dataset.id;
    if (!t) throw new Error("detail id 缺失");
    c.openPageMore(), wx.redirectTo({
      url: "/pages/detail/index?id=" + t
    });
  },
  backHandle: function () {
    wx.navigateBack({
      delta: 1
    });
  }
});